<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2009, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter HTML Helpers
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/helpers/html_helper.html
 */

// ------------------------------------------------------------------------

/**
 * Heading
 *
 * Generates an HTML heading tag.  First param is the data.
 * Second param is the size of the heading tag.
 *
 * @access	public
 * @param	string
 * @param	integer
 * @return	string
 */
if ( ! function_exists('heading'))
{
	function heading($data = '', $h = '1')
	{
		return "<h".$h.">".$data."</h".$h.">";
	}
}
if(!function_exists('addButton')){
    function addButton($url,$title) {
        if($url == '#'){
            $url = '#';
        }else $url = site_url ($url);
	return "<a href='".$url."' class='add'><div class='icon button-add'></div>".$title."</a>";
        
    }
}
//-------------------------------------------------------------------------
/*
 * fungsi yang digunakan untuk menampilkan pesan setelah transaksi
 */
if(!function_exists('pesan')){
    function pesan($id){
        if($id == 1){
            //Menampilkan pesan berhasil untuk proses add dan edit data
            return "<div class='ok'><strong>Info!</strong> Proses penambahan atau perubahan data berhasil dilakukan</div>";
        }
        else if($id == 2){
            //Menampilkan pesan gagal untuk proses add dan edit data
            return "<div class='error'><strong>Alert:</strong> Proses penambahan atau perubahan gagal dilakukan</div>";
        }
        else if($id == 3){
            //Menampilkan pesan berhasil untuk proses hapus data
            return "<div class='ok'><strong>Info!</strong> Proses penghapusan data berhasil dilakukan</div>";
        }
        else if($id == 4){
            //Menampilkan pesan gagal untuk proses hapus data
            return "<div class='error'><strong>Alert:</strong> Proses gagal (data yang akan dihapus digunakan untuk transaksi lain)</div>";
        }
        else if($id == 5){
            return "<div class='alert'>Maaf, password dan username Anda salah</div>";
        }
        else if($id == 6){
            return "<div class='alert'>Maaf, tidak diperkenankan mengakses tanpa login</div>";
        }
        else if($id == 7){
            //Menampilkan pesan berhasil untuk proses add dan edit data
            return "<div class='ok'><strong>Info!</strong> Proses perangkingan calon adik asuh berhasil dilakukan</div>";
        }
        else if($id == 8){
            return "<div class='error'><strong>Alert:</strong> Adik asuh tersebut sudah menerima beasiswa pada tahun ajaran ini</div>";
        }else if($id == 9){
            return "<div class='ok'><strong>Info!</strong> Proses approve keuangan bulanan berhasil dilakukan</div>";
        }else if($id == 10){
            return "<div class='ok'><strong>Info!</strong> Proses unapprove keuangan bulanan berhasil dilakukan</div>";
        }    
    }
}
// ------------------------------------------------------------------------
/*
 * fungsi untuk mengubah format uang ke format integer
 */
if(!function_exists('currencyToNumber')){
    function currencyToNumber($a){
        return str_ireplace(".", "", $a);
    }
}
//-------------------------------------------------------------------------
/*
 * fungsi yang digunakan untuk memecah parameter pencarian 
 */
if(!function_exists('parsing_param1')){
    function parsing_param1($params){
        if($params != all){
          $array_row = explode("_", $params);
          $criteria[$array_row[0]] = $array_row[1];
        }
        return $criteria;
    }
}
if(!function_exists('parsing_param2')){
    function parsing_param2($params){
//        $params = array();
        if($params != "all"){
            $params = explode("__", $params);
            foreach ($params as $row){
                $array_row = explode("_", $row);
                $criteria[$array_row[0]] = $array_row[1];
            }
        }
        return $criteria;
    }
}
//-------------------------------------------------------------------------
/*
 * fungsi untuk membuat format rupiah
 */
if(!function_exists('rupiah')){
    function rupiah($jml) {
            $int = number_format($jml, 0, '','.');
            return $int.',00';
    }
}
if(!function_exists('numberToCurrency')){
    function numberToCurrency($jml) {
            $int = number_format($jml, 0, '','.');
            return $int;
    }
}
//-------------------------------------------------------------------------
/*
 * Fungsi mengembalikan form dropdown
 */
if(!function_exists('dropdownPredikat')){
    function dropdownPredikat($name,$id){
       $string = "";
       $string .= "<select name='$name' id='$id' class='predikat'>";
       $string .= "<option value=''>Pilih predikat</option>";
       $string .= "<option value='A'>A</option>";
       $string .= "<option value='B'>B</option>";
       $string .= "<option value='C'>C</option>";
       $string .= "<option value='D'>D</option>";
       $string .= "</select>";
       
       return $string;
    }
}
//-------------------------------------------------------------------------
/*
 * fungsi untuk menghitung selisih hari
 */
if(!function_exists('selisihHari')){
    function selisihHari($startDate, $endDate) {
        $tgl1 = $startDate;  // 2009-10-01
        $tgl2 = $endDate;  // 2009-10-10
        // memecah tanggal untuk mendapatkan bagian tanggal, bulan dan tahun
        // dari tanggal pertama
    //    echo "$tgl1 $tgl2";
        $pecah1 = explode("-", $tgl1);

        $date1 = $pecah1[2];
        $month1 = $pecah1[1];
        $year1 = $pecah1[0];

        // memecah tanggal untuk mendapatkan bagian tanggal, bulan dan tahun
        // dari tanggal kedua

        $pecah2 = explode("-", $tgl2);
        $date2 = $pecah2[2];
        $month2 = $pecah2[1];
        $year2 = $pecah2[0];

        // menghitung JDN dari masing-masing tanggal

        $jd1 = GregorianToJD($month1, $date1, $year1);
        $jd2 = GregorianToJD($month2, $date2, $year2);

        // hitung selisih hari kedua tanggal

        $selisih = $jd2 - $jd1;
        return $selisih;
    }
}
//-------------------------------------------------------------------------
/*
 * Fungsi yang mengembalikan tanggal awal bulan dan akhir bulan
 * 
 */
if(!function_exists('betweenDate')){
    function betweenDate($bulan,$tahun){
        if($bulan==01){
                $date2 = ($tahun-1)."-12-01";
        }else{
                $date2 = $tahun."-".($bulan-1)."-01";
        }
        $date1 = $tahun."-".$bulan."-01";
        $hari = selisihHari($date2, $date1);
        $date3 = $tahun."-".$bulan."-".$hari;
        
        $return['awal'] = $date1;
        $return['akhir'] = $date3;
        
        return $return;
    }
}
//-------------------------------------------------------------------------
/*
 * fungsi yang digunakan untuk mendapatkan list bulan dari hasil pencarian
 */
if(!function_exists('bln')){
function bln($bln,$thawal,$thakhir) {
    $n = $thakhir - $thawal;
    if ($n >= 0) {
        for ($i = 0; $i <= $n; $i++) {
            switch ($bln) {
                case 1 + ($i * 12):
                    $val = "Januari";
                    break;

                case 2 + ($i * 12):
                    $val = "Februari";
                    break;

                case 3 + ($i * 12):
                    $val = "Maret";
                    break;

                case 4 + ($i * 12):
                    $val = "April";
                    break;

                case 5 + ($i * 12):
                    $val = "Mei";
                    break;

                case 6 + ($i * 12):
                    $val = "Juni";
                    break;

                case 7 + ($i * 12):
                    $val = "Juli";
                    break;

                case 8 + ($i * 12):
                    $val = "Agustus";
                    break;

                case 9 + ($i * 12):
                    $val = "September";
                    break;

                case 10 + ($i * 12):
                    $val = "Oktober";
                    break;

                case 11 + ($i * 12):
                    $val = "November";
                    break;

                case 12 + ($i * 12):
                    $val = "Desember";
                    break;
            }
        }
        return $val;
    }
}
}
//----------------------------------------------------------------
/*
 * Untuk mendapatkan bulan dalam format angka dari format nama bulan
 */
if(!function_exists('blnAngka')){
function blnAngka($bln) {
    $val = "0";
    switch ($bln) {
        case "Januari":
            $val = "1";
            break;

        case "Februari":
            $val = "2";
            break;

        case "Maret":
            $val = "3";
            break;

        case "April":
            $val = "4";
            break;

        case "Mei":
            $val = "5";
            break;

        case "Juni":
            $val = "6";
            break;

        case "Juli":
            $val = "7";
            break;

        case "Agustus":
            $val = "8";
            break;

        case "September":
            $val = "9";
            break;

        case "Oktober":
            $val = "10";
            break;

        case "November":
            $val = "11";
            break;

        case "Desember":
            $val = "12";
            break;
    }
    return $val;
}
}

if(!function_exists('blnHuruf')){
function blnHuruf($bln) {
    $val = "";
    switch ($bln) {
        case "01":
            $val = "Jan";
            break;

        case "02":
            $val = "Feb";
            break;

        case "03":
            $val = "Mar";
            break;

        case "04":
            $val = "Apr";
            break;

        case "05":
            $val = "Mei";
            break;

        case "06":
            $val = "Jun";
            break;

        case "07":
            $val = "Jul";
            break;

        case "08":
            $val = "Agt";
            break;

        case "09":
            $val = "Sep";
            break;

        case "10":
            $val = "Okt";
            break;

        case "11":
            $val = "Nov";
            break;

        case "12":
            $val = "Des";
            break;
    }
    return $val;
}
}
//---------------------------------------------------------------------------
/*
 * Ex : 102001 menjadi Jan 2001
 */
if ( ! function_exists('changePeriod'))
{
    function changePeriod($period){
        $bln = substr($period, 0, 2);
        $bln = blnHuruf($bln);
        
        $thn = substr($period, 2, 4);
        return $bln." ".$thn;
    }
}
//---------------------------------------------------------------------------
/*
 * Fungsi mengubah tanggal menjadi tanggal dengan format bhs.indonesia
 */
if ( ! function_exists('indo_tgl'))
{
function indo_tgl($tgl, $type=null) {
    if ($type == null) {
        $type = "/";
    }
    $tgl = explode($type, $tgl);
    if ($tgl[1] == '01')
        $mo = "Januari";
    if ($tgl[1] == '02')
        $mo = "Februari";
    if ($tgl[1] == '03')
        $mo = "Maret";
    if ($tgl[1] == '04')
        $mo = "April";
    if ($tgl[1] == '05')
        $mo = "Mei";
    if ($tgl[1] == '06')
        $mo = "Juni";
    if ($tgl[1] == '07')
        $mo = "Juli";
    if ($tgl[1] == '08')
        $mo = "Agustus";
    if ($tgl[1] == '09')
        $mo = "September";
    if ($tgl[1] == '10')
        $mo = "Oktober";
    if ($tgl[1] == '11')
        $mo = "November";
    if ($tgl[1] == '12')
        $mo = "Desember";
    $new = "$tgl[0] $mo $tgl[2]";

    return $new;
}
}
//---------------------------------------------------------------------------
/*
 * Fungsi untuk pencarian bulanan
 */
if ( ! function_exists('searchBulanan'))
{
    function searchBulanan($bln1,$bln2,$thawal,$thakhir){
?>
    <div class="monthly-selector">
            <input type=button class="prev-year-button" name="previousthawal" VALUE="" onClick="setPreviousthawal()">
            <input type=button class="prev-month-button" name="previousthawal" VALUE="" onClick="setPreviousbln1()">
            <select name="bln1" onChange="selectDate()" class="month" id="bln1">
                    <option value="Januari" <?php if($bln1 == "Januari") echo "selected";?>>January</option>
                    <option value="Februari" <?php if($bln1 == "Februari") echo "selected";?>>February</option>
                    <option value="Maret" <?php if($bln1 == "Maret") echo "selected";?>>March</option>
                    <option value="April" <?php if($bln1 == "April") echo "selected";?>>April</option>
                    <option value="Mei" <?php if($bln1 == "Mei") echo "selected";?>>May</option>
                    <option value="Juni" <?php if($bln1 == "Juni") echo "selected";?>>June</option>
                    <option value="Juli" <?php if($bln1 == "Juli") echo "selected";?>>July</option>
                    <option value="Agustus" <?php if($bln1 == "Agustus") echo "selected";?>>August</option>
                    <option value="September" <?php if($bln1 == "September") echo "selected";?>>September</option>
                    <option value="Oktober" <?php if($bln1 == "Oktober") echo "selected";?>>October</option>
                    <option value="November" <?php if($bln1 == "November") echo "selected";?>>November</option>
                    <option value="Desember" <?php if($bln1 == "Desember") echo "selected";?>>December</option>
            </select>
            <input name="thawal" type=TEXT SIZE=4 MAXLENGTH=4 value="<? echo "$thawal"; ?>" class="year" id="thawal">
            <input type=button class="next-month-button" name="previousthawal" VALUE="" onClick="setNextbln1()">
            <input type=button class="next-year-button" name="previousthawal" VALUE="" onClick="setNextthawal()">
            <span class="none">s . d</span>
            <input type=button name="previousthakhir" class="prev-year-button" VALUE="" onClick="setPreviousthakhir()">
	    <input type=button name="previousthakhir" class="prev-month-button" VALUE="" onClick="setPreviousbln2()">
	    <select name="bln2" onChange="selectDate()" class="month" id="bln2">
		<option value="Januari" <?php if($bln2 == "Januari") echo "selected";?>>January</option>
                <option value="Februari" <?php if($bln2 == "Februari") echo "selected";?>>February</option>
                <option value="Maret" <?php if($bln2 == "Maret") echo "selected";?>>March</option>
                <option value="April" <?php if($bln2 == "April") echo "selected";?>>April</option>
                <option value="Mei" <?php if($bln2 == "Mei") echo "selected";?>>May</option>
                <option value="Juni" <?php if($bln2 == "Juni") echo "selected";?>>June</option>
                <option value="Juli" <?php if($bln2 == "Juli") echo "selected";?>>July</option>
                <option value="Agustus" <?php if($bln2 == "Agustus") echo "selected";?>>August</option>
                <option value="September" <?php if($bln2 == "September") echo "selected";?>>September</option>
                <option value="Oktober" <?php if($bln2 == "Oktober") echo "selected";?>>October</option>
                <option value="November" <?php if($bln2 == "November") echo "selected";?>>November</option>
                <option value="Desember" <?php if($bln2 == "Desember") echo "selected";?>>December</option>
	    </select>
            <input name="thakhir" type=TEXT SIZE=4 MAXLENGTH=4 value="<? echo "$thakhir"; ?>" class="year" id="thakhir">
            <input type=button name="previousthakhir" class="next-month-button" VALUE="" onClick="setNextbln2()">
            <input type=button name="previousthakhir" class="next-year-button" VALUE="" onClick="setNextthakhir()">
    </div>
<?php
    }
}
//---------------------------------------------------------------------------
/*
 * Fungsi untuk pencarian tahunan
 */
if(!function_exists('searchTahunan')){
    function searchTahunan($thawal,$thakhir){
?>
        <div class="monthly-selector">
            <input type="button" name="previousYear" value="" class="prev-year-button" onClick="setPreviousYear()">
            <input name="thawal" id="awal" type=text size=4 maxlength=4 class="year" onkeyup="Angka(this)" value="<? echo "$thawal";?>">
            <input type="button" name="previousYear" value="" class="next-year-button"  onClick="setNextYear()">
            <span class="none">s . d </span>
            <input type="button" name="previousakhir" value="" class="prev-year-button" onClick="setPreviousakhir()">
            <input name="thakhir" id="akhir" type=text size=4 maxlength=4 class="year" onkeyup="Angka(this)" value="<? echo "$thakhir";?>">
            <input type="button" name="previousakhir" value="" class="next-year-button" onClick="setNextakhir()">
        </div>
<?    
    }
}
//---------------------------------------------------------------------------
/**
 * Unordered List
 *
 * Generates an HTML unordered list from an single or multi-dimensional array.
 *
 * @access	public
 * @param	array
 * @param	mixed
 * @return	string
 */
if ( ! function_exists('ul'))
{
	function ul($list, $attributes = '')
	{
		return _list('ul', $list, $attributes);
	}
}

// ------------------------------------------------------------------------

/**
 * Ordered List
 *
 * Generates an HTML ordered list from an single or multi-dimensional array.
 *
 * @access	public
 * @param	array
 * @param	mixed
 * @return	string
 */
if ( ! function_exists('ol'))
{
	function ol($list, $attributes = '')
	{
		return _list('ol', $list, $attributes);
	}
}

// ------------------------------------------------------------------------

/**
 * Generates the list
 *
 * Generates an HTML ordered list from an single or multi-dimensional array.
 *
 * @access	private
 * @param	string
 * @param	mixed
 * @param	mixed
 * @param	intiger
 * @return	string
 */
if ( ! function_exists('_list'))
{
	function _list($type = 'ul', $list, $attributes = '', $depth = 0)
	{
		// If an array wasn't submitted there's nothing to do...
		if ( ! is_array($list))
		{
			return $list;
		}

		// Set the indentation based on the depth
		$out = str_repeat(" ", $depth);

		// Were any attributes submitted?  If so generate a string
		if (is_array($attributes))
		{
			$atts = '';
			foreach ($attributes as $key => $val)
			{
				$atts .= ' ' . $key . '="' . $val . '"';
			}
			$attributes = $atts;
		}

		// Write the opening list tag
		$out .= "<".$type.$attributes.">\n";

		// Cycle through the list elements.  If an array is
		// encountered we will recursively call _list()

		static $_last_list_item = '';
		foreach ($list as $key => $val)
		{
			$_last_list_item = $key;

			$out .= str_repeat(" ", $depth + 2);
			$out .= "<li>";

			if ( ! is_array($val))
			{
				$out .= $val;
			}
			else
			{
				$out .= $_last_list_item."\n";
				$out .= _list($type, $val, '', $depth + 4);
				$out .= str_repeat(" ", $depth + 2);
			}

			$out .= "</li>\n";
		}

		// Set the indentation for the closing tag
		$out .= str_repeat(" ", $depth);

		// Write the closing list tag
		$out .= "</".$type.">\n";

		return $out;
	}
}

// ------------------------------------------------------------------------

/**
 * Generates HTML BR tags based on number supplied
 *
 * @access	public
 * @param	integer
 * @return	string
 */
if ( ! function_exists('br'))
{
	function br($num = 1)
	{
		return str_repeat("<br />", $num);
	}
}

// ------------------------------------------------------------------------

/**
 * Image
 *
 * Generates an <img /> element
 *
 * @access	public
 * @param	mixed
 * @return	string
 */
if ( ! function_exists('img'))
{
	function img($src = '', $index_page = FALSE)
	{
		if ( ! is_array($src) )
		{
			$src = array('src' => $src);
		}

		$img = '<img';

		foreach ($src as $k=>$v)
		{

			if ($k == 'src' AND strpos($v, '://') === FALSE)
			{
				$CI =& get_instance();

				if ($index_page === TRUE)
				{
					$img .= ' src="'.$CI->config->site_url($v).'" ';
				}
				else
				{
					$img .= ' src="'.$CI->config->slash_item('base_url').$v.'" ';
				}
			}
			else
			{
				$img .= " $k=\"$v\" ";
			}
		}

		$img .= '/>';

		return $img;
	}
}

// ------------------------------------------------------------------------

/**
 * Doctype
 *
 * Generates a page document type declaration
 *
 * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame,
 * html4-strict, html4-trans, and html4-frame.  Values are saved in the
 * doctypes config file.
 *
 * @access	public
 * @param	string	type	The doctype to be generated
 * @return	string
 */
if ( ! function_exists('doctype'))
{
	function doctype($type = 'xhtml1-strict')
	{
		global $_doctypes;

		if ( ! is_array($_doctypes))
		{
			if ( ! require_once(APPPATH.'config/doctypes.php'))
			{
				return FALSE;
			}
		}

		if (isset($_doctypes[$type]))
		{
			return $_doctypes[$type];
		}
		else
		{
			return FALSE;
		}
	}
}

// ------------------------------------------------------------------------

/**
 * Link
 *
 * Generates link to a CSS file
 *
 * @access	public
 * @param	mixed	stylesheet hrefs or an array
 * @param	string	rel
 * @param	string	type
 * @param	string	title
 * @param	string	media
 * @param	boolean	should index_page be added to the css path
 * @return	string
 */
if ( ! function_exists('link_tag'))
{
	function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
	{
		$CI =& get_instance();

		$link = '<link ';

		if (is_array($href))
		{
			foreach ($href as $k=>$v)
			{
				if ($k == 'href' AND strpos($v, '://') === FALSE)
				{
					if ($index_page === TRUE)
					{
						$link .= ' href="'.$CI->config->site_url($v).'" ';
					}
					else
					{
						$link .= ' href="'.$CI->config->slash_item('base_url').$v.'" ';
					}
				}
				else
				{
					$link .= "$k=\"$v\" ";
				}
			}

			$link .= "/>";
		}
		else
		{
			if ( strpos($href, '://') !== FALSE)
			{
				$link .= ' href="'.$href.'" ';
			}
			elseif ($index_page === TRUE)
			{
				$link .= ' href="'.$CI->config->site_url($href).'" ';
			}
			else
			{
				$link .= ' href="'.$CI->config->slash_item('base_url').$href.'" ';
			}

			$link .= 'rel="'.$rel.'" type="'.$type.'" ';

			if ($media	!= '')
			{
				$link .= 'media="'.$media.'" ';
			}

			if ($title	!= '')
			{
				$link .= 'title="'.$title.'" ';
			}

			$link .= '/>';
		}


		return $link;
	}
}

// ------------------------------------------------------------------------

/**
 * Generates meta tags from an array of key/values
 *
 * @access	public
 * @param	array
 * @return	string
 */
if ( ! function_exists('meta'))
{
	function meta($name = '', $content = '', $type = 'name', $newline = "\n")
	{
		// Since we allow the data to be passes as a string, a simple array
		// or a multidimensional one, we need to do a little prepping.
		if ( ! is_array($name))
		{
			$name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
		}
		else
		{
			// Turn single array into multidimensional
			if (isset($name['name']))
			{
				$name = array($name);
			}
		}

		$str = '';
		foreach ($name as $meta)
		{
			$type 		= ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv';
			$name 		= ( ! isset($meta['name'])) 	? '' 	: $meta['name'];
			$content	= ( ! isset($meta['content']))	? '' 	: $meta['content'];
			$newline	= ( ! isset($meta['newline']))	? "\n"	: $meta['newline'];

			$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
		}

		return $str;
	}
}

// ------------------------------------------------------------------------

/**
 * Generates non-breaking space entities based on number supplied
 *
 * @access	public
 * @param	integer
 * @return	string
 */
if ( ! function_exists('nbs'))
{
	function nbs($num = 1)
	{
		return str_repeat("&nbsp;", $num);
	}
}


/* End of file html_helper.php */
/* Location: ./system/helpers/html_helper.php */